/**
 * gislin 2017年8月24日
 */
package com.hrt.common.db;

import com.btcode.orm.executer.IORMExecuter;
import com.btcode.orm.model.IDomainField;
import com.btcode.orm.model.IField;
import com.hrt.common.systemmanager.systemsetting.dict.data.BcDictDataModel;
import java.io.Serializable;

/**
 * @author gislin 针对：字典映射处理 2017年8月24日
 */
public class DictDomainField implements IDomainField, Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private String dictTypeCode;

    private String fieldAliasName;

    private IField fieldName;

    /**
     *
     * @param dictTypeCode
     *            字典类型
     * @param fieldName
     *            本表字段
     * @param fieldAliasName
     *            映射出来的别名
     */
    public DictDomainField(String dictTypeCode, IField fieldName) {
        this.dictTypeCode = dictTypeCode;
        this.fieldName = fieldName;
        this.fieldAliasName = fieldName.getFieldName() + "_DESC";
    }

    @Override
    public Object getDomainValue(Object fieldValue, IORMExecuter ormExecuter) {

        if (fieldValue == null) {
            return null;
        }

        BcDictDataModel dictDataModel = new BcDictDataModel();
        dictDataModel.setDictTypeCode(dictTypeCode);
        dictDataModel.setCode(fieldValue.toString());

        dictDataModel = ormExecuter.getModel(dictDataModel);

        if (dictDataModel == null) {
            return null;
        }

        return dictDataModel.getValue();
    }

    @Override
    public IField getFieldName() {
        // TODO Auto-generated method stub
        return fieldName;
    }

    @Override
    public String getDomainFieldAliasName() {
        // TODO Auto-generated method stub
        return fieldAliasName;
    }

}
